//
//  BaseNavigationController.m
//  Business Club
//
//  Created by 范琦 on 16/4/7.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "BaseNavigationController.h"
#import "UIImage+YYAdd.h"

@interface BaseNavigationController ()<UINavigationControllerDelegate>

@end

@implementation BaseNavigationController


- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController];
    if (self) {
        self.navigationBar.translucent = NO;
        self.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationBar.shadowImage = [UIImage new];
        //这里我们设置的是颜色，还可以设置shadow等，具体可以参见api
        NSDictionary * dict = @{NSForegroundColorAttributeName :[UIColor blackColor], NSFontAttributeName : [UIFont systemFontOfSize:16]};
        //大功告成
        self.navigationBar.titleTextAttributes = dict;
        self.delegate = self;
        
        UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 20)];
        
        statusBarView.backgroundColor=[UIColor tiankonglan];
        
        [self.view addSubview:statusBarView];
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    }

    return self;
}
- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    
    if (viewController.navigationItem.leftBarButtonItem == nil && [navigationController viewControllers].count > 1) {
        UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(_didClickBackBarButtonItem:)];
        barButtonItem.tintColor = [UIColor redColor];
        viewController.navigationItem.leftBarButtonItem = barButtonItem;
    }
}
// 使状态栏文字变为白色
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)_didClickBackBarButtonItem:(id)sender
{

//    [self popViewControllerAnimated:YES];
 
        [self popViewControllerAnimated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
